﻿$(function () {
    //返回列表页
    $('.returnList').click(function () {
        var url = window.location.href;
        //url = url.replace('M/Detail/1194', 'MList')
        //url = url.replace(/[?=(/)+M/Detail/]+\d{4,}/g, "MList")
        //url = url.replace(/[?=(/)+M/Detail/]+\d{4,}/g, "/MList")
        //window.location = url;
    });
    //首页搜索
    $('.nameSearch').click(function () {
        $('.searchMain').animate({ opacity: '1', top: '0', height: '100%' }, 500, 'ease-in-out', function () { });
    });
    $('.searchTitle em').click(function () {
        $('.searchMain').animate({ opacity: '0', top: '100%', height: '0' }, 500, 'ease-in-out', function () { $('.pricePop').hide(); });
    });
    $(".searchInput input").focus(function () { if ($(this).val() == "按月嫂姓名或者ID搜") { $(this).val('').addClass("on"); } });
    $(".searchInput input").blur(function () { if ($(this).val() == "") { $(this).val('按月嫂姓名或者ID搜').removeClass("on"); } });

    $('.scrList').on('click', 'a', function () {
        $(this).toggleClass('active');
        var $dl = $(this).closest("dl");
        var showDown = $($dl).find(".show_down");
        var showUp = $($dl).find(".show_up");
        var arr = [];
        $.each($($dl).find("a.active"), function(index,item) {
            arr.push($(item).html());
        });
        var showDownHtml = arr.join(",");
        $(showDown).html(showDownHtml);
        if (showDownHtml) {
            $(showUp).hide();
            $(showDown).show();
        } else {
            //$(showUp).show();
            //$(showDown).hide();
        }
    });
    $(".scrEmpty").bind("click" , function() {
        $(".scrList a").removeClass("active");
        $(".scrBack .show_up").show();
        $(".scrBack .show_down").hide();
    });
    $('.screening').click(function () {
        $('html').addClass('sift-move');
        //var oHeight = getClientHeight() - 100;
        var oHeight = document.documentElement.clientHeight - 0;
        var oBack = getScrollHeight();
        $('.scrBack').css({ 'height': oHeight });
        $('.scrRolling').css({ 'height': oHeight });
        $('.scrDown').css({ 'height': oBack });
        $('.scrPop,.scrMenu').show();

    });
    $('.scrDown').click(function () {
        $('html').addClass('sift-back');
        setTimeout(function () {
            $('html').attr('class', '');
            $('.scrPop,.scrMenu').hide();
        }, 200);


    });
    $('.scrBack dt').click(function () {
        $(this).toggleClass('up');
        $(this).parents('dl').toggleClass('click');
        $(this).parents('dl').find('dd').toggle();
        //$(this).parents('dl').find('.show_up,.show_down').toggle();
        var showDown = $(this).parents('dl').find('.show_down').html();
        if (!showDown) {
            $(this).parents('dl').find('.show_up').show();
            $(this).parents('dl').find('.show_down').hide();
        } else {
            $(this).parents('dl').find('.show_up').hide();
            $(this).parents('dl').find('.show_down').show();
        }
    });

    $('.productList li').click(function () {
        var url = $(this).attr('domo-url');
        window.location = url;
    });


    //首页月嫂薪酬范围
    $('.priceHome').click(function () {

        $('.pricePop').show();
        $('.pricePop').animate({ opacity: '1', top: '120px' }, 800, 'ease-in-out', function () { });
        //$('.pricePop').animate({opacity:'1'},500,'ease-in-out',function(){});
        $('.pricePop').on('click', 'li', function () {
            $('.home-price').html($(this).html());
            $('.home-price').data("raw-value", $(this).data("raw-value"));
            $('.pricePop').animate({ opacity: '0', top: '400px' }, 800, 'ease-in-out', function () { $('.pricePop').hide(); });
        });
    });
    //首页月嫂经验
    $('.yearHome').click(function () {
        $('.yearPop').show();
        $('.yearPop').animate({ opacity: '1', top: '120px' }, 800, 'ease-in-out', function () { });
        $('.yearPop').on('click', 'li', function () {
            $('.home-year').html($(this).html());
            $('.home-year').data("raw-value", $(this).data("raw-value"));
            $('.yearPop').animate({ opacity: '0', top: '400px' }, 800, 'ease-in-out', function () { $('.yearPop').hide(); });
        });
    });

    //返回顶部
    $('body').append('<a href="#" title="回到顶部" class="ysGoTop">回到顶部</a>')
    function returnTop() {
        var oScroll = getScrollTop();
        if (oScroll > $(window).height()) {
            $('.ysGoTop').animate({ opacity: '1' }, 800, 'ease-in-out', function () { $('.ysGoTop').show(); });
        } else {
            $('.ysGoTop').animate({ opacity: '0' }, 800, 'ease-in-out', function () { $('.ysGoTop').hide(); });
        }
    }
    $(window).scroll(function () {
        returnTop();
    });

    //提交面试取消原因
    $('.why').on('click', 'li', function () {
        var oVal = $(this).find('.radio_text').html();
        $(this).addClass('active').siblings().removeClass('active');
    });
    $('.subWhy').click(function () {
        var oVal_1 = $('.why .active').find('span').html();
        var oVal_2 = $('.orderMenu .addText').val();
        alert('您提交了' + oVal_1 + '和' + oVal_2);
    });

    //微信分享
    detailShare();

});


function sel_date_show() {
    if ($('.scrResults ').length != 0) {
        $('.sel_date').animate({ opacity: '1', top: '-170px' }, 800, 'ease-in-out', function () { });
    } else {
        $('.sel_date').animate({ opacity: '1', top: '-300px' }, 800, 'ease-in-out', function () { });
    }

}
function sel_date_hide() {
    $('.sel_date').animate({ opacity: '0', top: '500px' }, 800, 'ease-in-out', function () {
        if (close != false) {
            $('.sel_date').addClass('dn');
        }
    });
}

//微信分享
function detailShare() {
    if ($('.yuesaoName').length != 0) {
        var imgUrl = $('.userImg img').attr('src');
        var lineLink = window.location.href;
        var descContent = $('.skillLevel span').text() +'--'+ $('.userInfo').find('p').eq(0).text()+'。' + $('.skillLevel').next().text();
        var shareTitle = '分享自#安心客#' + $('.yuesaoName').text()+'的基本信息！';
        var appid = '';
        descContent = descContent.replace(/[ ]/g, "");
    } else {
        var imgUrl = 'http://www.iyuesao.com/content/images/iyuesaoShare.jpg';
        var lineLink = window.location.href;
        var descContent = '安心客网是北京地区星级月嫂最多，服务最专业的北京月嫂信息服务平台。安心客为您精选出好口碑、经过专业培训、职业资格证和健康证齐全的月嫂。安心客，帮你找到好月嫂！';
        var shareTitle = '安心客_北京最专业的月嫂信息服务平台。安心客，帮你找到好月嫂！';
        var appid = '';
    }
    function shareFriend() {
        WeixinJSBridge.invoke('sendAppMessage', {
            "appid": appid,
            "img_url": imgUrl,
            "img_width": "200",
            "img_height": "200",
            "link": lineLink,
            "desc": descContent,
            "title": shareTitle
        }, function (res) {
        })
    }
    function shareTimeline() {
        WeixinJSBridge.invoke('shareTimeline', {
            "img_url": imgUrl,
            "img_width": "200",
            "img_height": "200",
            "link": lineLink,
            "desc": descContent,
            "title": shareTitle
        }, function (res) {
        });
    }
    function shareWeibo() {
        WeixinJSBridge.invoke('shareWeibo', {
            "content": descContent,
            "url": lineLink,
        }, function (res) {
        });
    }
    // 当微信内置浏览器完成内部初始化后会触发WeixinJSBridgeReady事件。
    document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
        // 发送给好友
        WeixinJSBridge.on('menu:share:appmessage', function (argv) {
            shareFriend();
        });
        // 分享到朋友圈
        WeixinJSBridge.on('menu:share:timeline', function (argv) {
            shareTimeline();
        });
        // 分享到微博
        WeixinJSBridge.on('menu:share:weibo', function (argv) {
            shareWeibo();
        });
    }, false);
}





//月嫂详情页导航定温
$(document).ready(function () {
    if (window.location.href.toLowerCase().indexOf("detail") == -1) return;
    var oTop = $('.nav-tag').offset().top;
    var oReview = $('#review').offset().top;
    var oWorkSkills = $('#workSkills').offset().top;
    var oCharacters = $('#characters').offset().top;
    //var oInterview = $('#interview').offset().top;
    var oDocument = $(document).height() - $(window).height();
    $('.nav-tag li a').click(function () {
        var id = $(this).parent('li').attr('title');
        var top = $('#' + id).offset().top - 95;
        $(this).addClass("active");
        $(this).parent('li').siblings().find('a').removeClass("active");
        topScroll(top)
    });
    function topScroll(a) {
        window.scrollTo(0, a);
    }

    function scrollTop() {
        var oScroll = getScrollTop();
        //console.log(oScroll);
        if (oScroll > oTop) {
            $('.nav-tag').css({ 'position': 'fixed', 'top': '0', 'border-bottom': '#ccc solid 1px;' });
            $('.ys-detail').css('padding-top', '105px');
            //if (oScroll - oBaseInfo >= -95) {
            //    oActive(3);
            //} else if (oScroll - oCharacters >= -95) {
            //    oActive(2);
            //} else if (oScroll - oInterview >= -95) {
            //    oActive(1);
            //} else {
            //    oActive(0);
            //}
            if (oScroll - oReview >= -95) {
                oActive(3);
            } else if (oScroll - oCharacters >= -95) {
                oActive(2);
            } else if (oScroll - oWorkSkills >= -95) {
                oActive(1);
            } else {
                oActive(0);
            }
        } else {
            $('.nav-tag').css({ 'position': 'relative', 'top': '0', 'border-bottom': 'none' });
            $('.ys-detail').css('padding-top', '21px');
            oActive(0);
        }
        function oActive(n) {
            $('.nav-tag ul li').find('a').removeClass("active");
            $('.nav-tag ul li').eq(n).find('a').addClass("active");
            if (n >= 0) {
                $('.footerFix').css({ 'position': 'fixed' });
            } else {
                $('.footerFix').css({ 'position': 'relative' });
            }
        }
    }
    scrollTop();
    $(window).resize(function () {
        scrollTop();
    });
    $(window).scroll(function () {
        scrollTop();
    });

});


/*取窗口滚动条高度*/
function getScrollTop() {
    var scrollTop = 0;
    if (document.documentElement && document.documentElement.scrollTop) {
        scrollTop = document.documentElement.scrollTop;
    }
    else if (document.body) {
        scrollTop = document.body.scrollTop;
    }
    return scrollTop;
}


/*取窗口可视范围的高度*/
function getClientHeight() {
    var clientHeight = 0;
    if (document.body.clientHeight && document.documentElement.clientHeight) {
        var clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;
    }
    else {
        var clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;
    }
    return clientHeight;
}

/*取文档内容实际高度*/
function getScrollHeight() {
    return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
}

/*删除字符串中的空格*/
function Trim(m) {
    while ((m.length > 0) && (m.charAt(0) == ' '))
        m = m.substring(1, m.length);
    while ((m.length > 0) && (m.charAt(m.length - 1) == ' '))
        m = m.substring(0, m.length - 1);
    return m;
}